package com.lushuai.jiubeidanci.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.lushuai.jiubeidanci.R;

public class BannerAdapter extends RecyclerView.Adapter<BannerAdapter.BannerViewHolder> {
    
    private int[] bannerImages;
    
    public BannerAdapter(int[] bannerImages) {
        this.bannerImages = bannerImages;
    }
    
    @NonNull
    @Override
    public BannerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_banner, parent, false);
        return new BannerViewHolder(view);
    }
    
    @Override
    public void onBindViewHolder(@NonNull BannerViewHolder holder, int position) {
        if (bannerImages.length > 0) {
            int realPosition = position % bannerImages.length;
            holder.imageView.setImageResource(bannerImages[realPosition]);
        }
    }
    
    @Override
    public int getItemCount() {
        return bannerImages.length > 0 ? Integer.MAX_VALUE : 0;
    }
    
    static class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        
        public BannerViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.banner_image);
        }
    }
} 